1. Class No.33 Data Structures http://ecomputernotes.com
2.
3. Binary Search If ( value == middle element ) value is found else if ( value < middle element ) search left-half of list with the same method else search right-half of list with the same method http://ecomputernotes.com
4. Case 1: val == a[mid] val = 10 low = 0, high = 8 5 7 9 10 13 17 19 1 27 1 2 3 4 5 6 7 0 8 a: low high Binary Search mid mid = (0 + 8) / 2 = 4 10 http://ecomputernotes.com
5. Case 2: val > a[mid] val = 19 low = 0, high = 8 mid = (0 + 8) / 2 = 4 Binary Search -- Example 2 5 7 9 10 1 13 17 19 27 1 2 3 4 5 6 7 0 8 a: mid low high new low new low = mid+1 = 5 13 17 19 27 http://ecomputernotes.com
6. Case 3: val < a[mid] val = 7 low = 0, high = 8 mid = (0 + 8) / 2 = 4 Binary Search -- Example 3 10 13 17 19 5 7 9 1 27 1 2 3 4 5 6 7 0 8 a: mid low high new high new high = mid-1 = 3 5 7 9 1 http://ecomputernotes.com